* Michael Biggs, "Feminism and support for the transgender movement in Britain"
* Email: michael.biggs@sociology.ox.ac.uk
* Article accepted by Socius, 19 February 2024
* Version 2 of replication file, 19 March 2024: this corrects the weighting

cd "/Users/michael/Documents/Work/Social movements/Anti-trans movement/BES"

use "BES data/BES2019_W25_v25.0.dta", clear
* https://www.britishelectionstudy.com/data-object/wave-25-of-the-2014-2023-british-election-study-internet-panel/
save "~/.Trash/temp", replace

capture: file close r
file open r using "Results.tsv", write text replace

********************************************************************************
* RECODING
********************************************************************************

* Weighting
svyset [pweight=wt]

* Attitudes to transgender 
tab cwTrans
label list agreeDisagree
label copy agreeDisagree agreeDisagree6
label define agreeDisagree6 6 "Don't know", add
recode cwTrans (9999 = 6 "Don't know"), gen(cwTrans6) label(agreeDisagree6)
tab cwTrans6

label copy agreeDisagree agreeDisagree6o
recode cwTrans6 (6 = 4 "Don't know") (4 = 5 "Agree") (5 = 6 "Strongly agree"), gen(trans6o) label(agreeDisagree6o)
label var trans6o "Agreement with trans women competing in female sports; don't know coded in middle" 
tab trans6o cwTrans

count if trans6o!=.
svy: tab trans6o
file write r "Transgender women in female sports:" _n
file write r "% who strongly agree" _tab %3.0f ( e(Prop)[6,1]*100 ) _n
file write r "% who strongly disagree" _tab %3.0f ( e(Prop)[1,1]*100 ) _n

* Sex
tab gender
gen byte female = gender==2

* Feminism
svy: tab discrimWomen, miss
tab discrimWomen, nol
svy: tab discrimWomen
svy: tab discrimWomen female, row

gen byte feminist_scale = cond(discrimWomen==9999, 5, discrimWomen)
label var feminist_scale "How much sex discrimination? 0 (a lot against men) to 10 (a lot against women); don't know coded as 5"

gen byte feminist = discrimWomen==10
label var feminist "Believes that there is a lot of discrimination against women"
label define feminist 0 "non-feminist" 1 "feminist"
label values feminist feminist
tab discrimWomen feminist, miss
svy: tab feminist
file write r _n "Feminists:" _n
file write r "% who are feminist" _tab %3.0f ( e(Prop)[2,1]*100 ) _n
svy: tab female if feminist==1
file write r "% of feminists who are female" _tab %3.0f ( e(Prop)[2,1]*100 ) _n

********************************************************************************
* ANALYSIS
********************************************************************************

local condition "age<=80"

svy: mlogit trans6o feminist i.feminist##c.age##c.age##c.age if `condition'
testparm c.age#c.age#c.age feminist#c.age#c.age#c.age 

svy: mlogit trans6o i.feminist##c.age##c.age if `condition'
testparm c.age#c.age feminist#c.age#c.age 

local samplesize : display %6.0fc (e(N))
di "`samplesize'"

file write r _n "Number of individuals in model " _tab %6.0fc (e(N)) _n

file write r _n "Predicted probabilities from model:" _n
margins, at( age = (20) ) dydx(feminist) predict(outcome(6))
file write r "At age 20, prob for feminist - prob for nonfeminist to strongly agree (%age points)" ///
	_tab %3.0f (  r(table)[1,2]*100 ) _n
margins, at( age = (60) ) dydx(feminist) predict(outcome(1))
file write r "At age 60, prob for feminist - prob for nonfeminist to strongly DISAGREE (%age points)" ///
	_tab %3.0f (  r(table)[1,2]*100 ) _n

file close r



********************************************************************************
* FIGURES 1 AND A1
********************************************************************************

local color1 `""255 0 0""'
local color2 `""255 128 128""'
local color3 "gs11"
local color4 "gs8"
local color5 `""128 128 255""'
local color6 `""0 0 255""'

forvalues o = 1(1)6 {
	margins, at( age = (18(1)80) ) dydx(feminist) predict(outcome(`o'))
	local ytitle = cond(`o'==1 | `o'==6, "Difference in probability", "Difference")
	local title = cond(`o'==1 | `o'==6, "Feminist – Non-feminist", `""Feminist –" "Non-feminist""')
	marginsplot, name(conditional_`o', replace) ///
		plotopts(  lcolor(white) )   ciopts( color(`color`o'') )  ///
		recast(line) recastci(rarea)  ///
		title(`title', color(black) box bcolor(white) size(vlarge) margin(zero) position(12) ring(0)) /// 
		ytitle(`ytitle', size(large)) ///
		ylabel(-.2(.1).2, angle(0) grid glcolor(ltblue) labsize(large)) yscale(range(-.23 .23)) ///
		xtitle("")   xlabel(20(20)80, grid glcolor(ltblue) labsize(large))   xscale(noline) ///
		yline(0, lcolor(black)) ///
		legend(off) ///
		plotregion(margin(zero))      ///
		graphregion(fcolor(white) lcolor(white) margin(b=0 t=0 l=1 r=3))
	forvalues f = 0/1 {
		margins, at( age = (18(1)80) feminist = `f') predict(outcome(`o')) 
		local title = cond(`f'==0, "Non-feminist", "Feminist")
		marginsplot, name(prob_`f'_`o', replace) ///
			plotopts(  lcolor(white) )   ciopts( color(`color`o'') )  ///
			recast(line) recastci(rarea)  ///
			title(`title', color(black) box bcolor(white) size(vlarge) margin(zero) position(12) ring(0)) ///
			ytitle("Probability", size(large)) ///
			ylabel(0(.1).6, angle(0) grid glcolor(ltblue) labsize(large)) yscale(range(0 .65)) ///
			xtitle("")   xlabel(20(20)80, grid glcolor(ltblue) labsize(large))   ///
			legend(off) ///
			plotregion(margin(zero))      ///
			graphregion(fcolor(white) lcolor(white) margin(b=0 t=0 l=1 r=3))
		}
	}	

graph combine ///
	prob_0_6 prob_1_6 conditional_6  ///
	prob_0_1 prob_1_1 conditional_1, ///
	rows(2) xcommon ///
	graphregion(fcolor(white) lcolor(white) margin(small))  ///
	name(figure, replace)
	
* FIGURE 1

graph combine ///
	prob_1_6 prob_0_6 conditional_6  ///
	, rows(1) xcommon ///
	title("{bf:Strongly agree}", color(black) margin(b=4)) ///
	b1title("Age", size(medlarge)) ///
	graphregion(fcolor(white) lcolor(white) margin(small)) xsize(4) ysize(1.5)  ///
	name(figure_6, replace)
graph combine ///
	prob_1_1 prob_0_1 conditional_1  ///
	, rows(1) xcommon ///
	title("{bf:Strongly disagree}", color(black) margin(b=4)) ///
	b1title("Age", size(medlarge)) ///
	graphregion(fcolor(white) lcolor(white) margin(small)) xsize(4) ysize(1.5)  ///
	name(figure_1, replace)

graph combine figure_6 figure_1, ///
	cols(1) ///
	graphregion(fcolor(white) lcolor(white) margin(zero)) 
graph export figures/figure1.jpg, as(jpg) replace

* FIGURE A1

graph combine ///
	prob_1_5 prob_0_5 conditional_5  ///
	, rows(1) xcommon ///
	title("{bf:Agree [weakly]}", color(black) margin(b=2) size(medlarge)) ///
	b1title("Age", size(medlarge)) ///
	graphregion(fcolor(white) lcolor(white) margin(small)) xsize(4) ysize(1.5)  ///
	name(figure_5, replace)
graph combine ///
	prob_1_4 prob_0_4 conditional_4  ///
	, rows(1) xcommon ///
	title("{bf:Don`=ustrunescape("\u2019")'t know}", color(black) margin(b=2) size(medlarge)) ///
	b1title("Age", size(medlarge)) ///
	graphregion(fcolor(white) lcolor(white) margin(small)) xsize(4) ysize(1.5)  ///
	name(figure_4, replace)
graph combine ///
	prob_1_3 prob_0_3 conditional_3  ///
	, rows(1) xcommon ///
	title("{bf:Neither agree nor disagree}", color(black) margin(b=2) size(medlarge)) ///
	b1title("Age", size(medlarge)) ///
	graphregion(fcolor(white) lcolor(white) margin(small)) xsize(4) ysize(1.5)  ///
	name(figure_3, replace)
graph combine ///
	prob_1_2 prob_0_2 conditional_2  ///
	, rows(1) xcommon ///
	title("{bf:Disagree [weakly]}", color(black) margin(b=2) size(medlarge)) ///
	b1title("Age", size(medlarge)) ///
	graphregion(fcolor(white) lcolor(white) margin(small)) xsize(4) ysize(1.5)  ///
	name(figure_2, replace)
	
graph combine ///
	figure_5  ///
	figure_4  ///
	figure_3  ///
	figure_2  ///
	, cols(1) xcommon ///
	graphregion(fcolor(white) lcolor(white) margin(zero)) ysize(7) ///
	name(fullfigure, replace)
graph export figures/figureA1.jpg, as(jpg) replace


********************************************************************************
* FIGURE A2
********************************************************************************

frame copy default graphwrite, replace
frame change graphwrite

sort age

forvalues f = 1(-1)0 {
	replace feminist = `f'
	local l = cond(`f'==0, "Non-feminist", "Feminist")
	predict double pr`f'_*
	replace pr`f'_2 = pr`f'_1 + pr`f'_2
	replace pr`f'_3 = pr`f'_2 + pr`f'_3
	replace pr`f'_4 = pr`f'_3 + pr`f'_4
	replace pr`f'_5 = pr`f'_4 + pr`f'_5
	replace pr`f'_6 = pr`f'_5 + pr`f'_6
	assert reldif(pr`f'_6,1) < 1e-6
	if `f'==1 {	
		local text = 		      `"text(.30 65 "Strongly disagree", size(medlarge) place(c)) "' 
		local text = `"`text'"' + `"text(.67 70 "Disagree", size(medlarge) place(c)) "'
		local text = `"`text'"' + `"text(.80 60 "Neither agree nor disagree", size(medlarge) place(c)) "'
		local text = `"`text'"' + `"text(.86 52 "Don`=ustrunescape("\u2019")'t know", size(medlarge) place(c)) "'
		local text = `"`text'"' + `"text(.92 50 "Agree", size(medlarge) place(c)) "'
		local text = `"`text'"' + `"text(.97 32 "Strongly agree",  color(white) size(medlarge) place(c)) "'
		di `"`text'"'
		}
	else {
		local text = ""		
		local lines = 		      "( line pr1_5 age , lcolor(black) lpattern(dash) ) "
		local lines = "`lines'" + "( line pr1_4 age , lcolor(black) lpattern(dash) ) "
		local lines = "`lines'" + "( line pr1_3 age , lcolor(black) lpattern(dash) ) "
		local lines = "`lines'" + "( line pr1_2 age , lcolor(black) lpattern(dash) ) "
		local lines = "`lines'" + "( line pr1_1 age , lcolor(black) lpattern(dash) ) "
		di "`lines'"
		}
	twoway ///
		( area pr`f'_6 age, color(`color6') )             ///
		( area pr`f'_5 age, color(`color5') )             ///
		( area pr`f'_4 age, color(`color4') )             ///
		( area pr`f'_3 age, color(`color3') )             ///
		( area pr`f'_2 age, color(`color2') )             ///
		( area pr`f'_1 age, color(`color1') ) ///
		`lines'		///
		if age<=80,               ///
			title("`l'", color(black) size(vlarge) ) ///
		   xlabel(20(20)80, grid labsize(large))  xtitle("")           ///
		   ylabel(0(.2)1, angle(0) grid labsize(large))  ytitle("Predicted cumulative probability", size(large))   ///
		   plotregion(margin(zero))      ///
		   graphregion(fcolor(white) lcolor(white) margin(b=0 t=0 l=1 r=3)) ///
		   legend(off) ///
		   `text' ///
		   name(cum`f', replace)
		 *	drop pr`f'_1-pr`f'_6
	}
graph combine cum1 cum0, ///
	graphregion(fcolor(white) lcolor(white) margin(small)) 
graph export figures/figureA2.jpg, as(jpg) replace

frame change default

********************************************************************************
* TREAT FEMINISM AS A SCALE: FIGURE A3
********************************************************************************

svy: mlogit trans6o c.feminist_scale##c.feminist_scale##c.age##c.age if `condition'
testparm c.feminist_scale#c.feminist_scale#c.age#c.age

* Young: pro-trans
margins, at( age = (20) feminist_scale=(0(1)10) )  predict(outcome(6))
margins, at(age=20 feminist_scale=(5 10) )  predict(outcome(6)) contrast(atcontrast(r._at))

* Old: pro-trans
margins, at( age = (60) feminist_scale=(0 5 9 10) )  predict(outcome(6))
margins, at(age=60 feminist_scale=(5 10) )  predict(outcome(6)) contrast(atcontrast(r._at))

* Old: anti-trans
margins, at( age = (60) feminist_scale=(0 5 9 10) )  predict(outcome(1))
margins, at(age=60 feminist_scale=(5 10) )  predict(outcome(1)) contrast(atcontrast(r._at))
margins, at(age=60 feminist_scale=(9 10) )  predict(outcome(1)) contrast(atcontrast(r._at))
margins, at(age=60 feminist_scale=(8 10) )  predict(outcome(1)) contrast(atcontrast(r._at))

forvalues o = 1(5)6 { 
	foreach a in 20 60 {
		margins, at( age = (`a') feminist_scale=(0(1)10)) predict(outcome(`o')) 
		local title = "Age `a'"
		marginsplot, name(prob_scale_age`a'_outcome`o', replace) ///
			plotopts(  lcolor(white) lwidth(vthin) )   ciopts( color(`color`o'') )  ///
			recast(line) recastci(rarea)  ///
			title(`title', color(black) box bcolor(white) size(vlarge) margin(zero) position(12) ring(0)) ///
			ytitle("Probability", size(large)) ///
			ylabel(0(.2).8, angle(0) grid glcolor(ltblue) labsize(large)) yscale(range(0 .89)) ///
			xtitle("") xmtick(0(1)10, grid glcolor(ltblue)) ///
			xlabel(0 5 10, grid glcolor(ltblue) labsize(large))   ///
			legend(off) ///
			plotregion(margin(zero))      ///
			graphregion(fcolor(white) lcolor(white) margin(b=0 t=0 l=1 r=3))
		}
	}	
graph combine ///
	prob_scale_age20_outcome6 prob_scale_age60_outcome6  ///
	, rows(1) xcommon ///
	title("{bf:Strongly agree}", color(black) margin(b=4)) ///
	b1title("Society discriminates against men (0) ... against women (10)", size(medlarge)) ///
	graphregion(fcolor(white) lcolor(white) margin(small)) xsize(4) ysize(1.5)  ///
	name(figure_scale_outcome6, replace)
graph combine ///
	prob_scale_age20_outcome1 prob_scale_age60_outcome1  ///
	, rows(1) xcommon ///
	title("{bf:Strongly disagree}", color(black) margin(b=4)) ///
	b1title("Society discriminates a lot against men (0) ... a lot against women (10)", size(medlarge)) ///
	graphregion(fcolor(white) lcolor(white) margin(small)) xsize(4) ysize(1.5)  ///
	name(figure_scale_outcome1, replace)
graph combine figure_scale_outcome6 figure_scale_outcome1, ///
	cols(1) ///
	graphregion(fcolor(white) lcolor(white) margin(zero)) 
graph export figures/figureA3.jpg, as(jpg) replace

